@echo off

rem informations auto-inserees dans les fichiers
set VERSION=1.0.0
set MONTH=%DATE:~3,2%
set YEAR=%DATE:~6%
set COPYRIGHT=Copyright (C) %YEAR% WYNIWYG. All rights reserved.
set LICENSE=http://www.gnu.org/copyleft/gpl.html GNU/GPL

set MAP=01-January;02-February;03-March;04-April;05-May;06-June;07-July;08-August;09-Septembre;10-Octobre;11-Novembre;12-Decembre
call set MONTH_TXT=%%MAP:*%MONTH%-=%%
set MONTH_TXT=%MONTH_TXT:;=&rem.%

set CHEMIN_SRC="%CD%"
set CHEMIN_PACKAGE_TMP=%CHEMIN_SRC%\packages\tmp

set UTIL_ARCHIVEUR=tools\7za.exe
if not exist %UTIL_ARCHIVEUR% (
	echo l'utilitaire d'archivage n'a pas ete trouve : %UTIL_ARCHIVEUR% !
	goto end
)

set UTIL_EDITEUR=tools\sed.exe
if not exist %UTIL_EDITEUR% (
	echo l'utilitaire d'edition n'a pas ete trouve : %UTIL_EDITEUR% !
	goto end
)

md %CHEMIN_PACKAGE_TMP%

echo.
echo copie des fichiers vers %CHEMIN_PACKAGE_TMP%
set REP_PLUGIN_COPIX=\administrator\components\com_jfusion\plugins\copix
copy %CHEMIN_SRC%%REP_PLUGIN_COPIX%\*.php %CHEMIN_PACKAGE_TMP%
copy %CHEMIN_SRC%%REP_PLUGIN_COPIX%\*.xml %CHEMIN_PACKAGE_TMP%
copy %CHEMIN_SRC%%REP_PLUGIN_COPIX%\*.html %CHEMIN_PACKAGE_TMP%

echo.
echo copie des fichiers de langues backend
echo en anglais
set REP_LANGUE_ADMIN=\administrator\language\en-GB
copy %CHEMIN_SRC%%REP_LANGUE_ADMIN%\*plg_copix.ini %CHEMIN_PACKAGE_TMP%
echo en francais
set REP_LANGUE_ADMIN=\administrator\language\fr-FR
copy %CHEMIN_SRC%%REP_LANGUE_ADMIN%\*plg_copix.ini %CHEMIN_PACKAGE_TMP%

rem recuperation de la revision SVN
for /f "tokens=*" %%a in ('svnversion') do ( set REVISION=%%a )
if "%REVISION:~-1%" == " " SET REVISION=%REVISION:~0,-1%
if "%REVISION:~-1%" == "P" SET REVISION=%REVISION:~0,-1%
if "%REVISION:~-1%" == "S" SET REVISION=%REVISION:~0,-1%
if "%REVISION:~-1%" == "M" SET REVISION=%REVISION:~0,-1%

echo.
echo mise a jour des ###donnees### dans les fichiers
for /F "delims=" %%a in ('dir /s /b /a-d %CHEMIN_PACKAGE_TMP% ^| findstr /v ".svn"') do (
	move "%%a" "%%a.tmp" 1>nul
	%UTIL_EDITEUR% -e "s|###FILE_NAME###|%%~nxa|g" -e "s|###YEAR###|%YEAR%|g" -e "s|###MONTH_TXT###|%MONTH_TXT%|g" -e "s|###REVISION###|%REVISION%|g" -e "s|###VERSION###|%VERSION%|g" -e "s|###COPYRIGHT###|%COPYRIGHT%|g" -e "s|###LICENSE###|%LICENSE%|g" "%%a.tmp" > "%%a"
	del "%%a.tmp"
)

echo.
echo creation de l'archive
set ARCHIVE=%CHEMIN_SRC%\packages\copix-plugin-for-jfusion_v%VERSION%.zip
del %ARCHIVE% 2>nul
%UTIL_ARCHIVEUR% a %ARCHIVE% %CHEMIN_PACKAGE_TMP%\* -xr!*.svn* >nul
echo suppression du repertoire temporaire
rmdir %CHEMIN_PACKAGE_TMP% /s /q

:end
pause
